﻿using DBLibrary.Model.pojo;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace DBLibrary.Model.pojo
{
    public class PagesUntils
    {
        private static int pageSize = 16;//每页显示数据5条

        public static int PageSize { get => pageSize; set => pageSize = value; }
        public static Pages GetPages(List<BrachStatus> SwitchData, int currentPage, int flag)
        {
            int size;
            //查询数据总数`
            if (SwitchData == null)
            {
                size = 0;
            }
            else
            {
                size = SwitchData.Count();
            }
            int pages;
            if (size > 0)
            {
                //计算总页数
                if (size % PageSize == 0)
                {
                    pages = size / PageSize;
                }
                else
                {
                    pages = size / PageSize + 1;
                }
            }
            else
            {
                pages = 1;
            }

            int button1 = 0;//定义按钮1的初始文本值
            int button2 = 0;//定义按钮2的初始文本值
            int button3 = 0;//定义按钮3的初始文本值
            int button4 = 0;//定义按钮4的初始文本值

            //初始化各种判断条件
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;
            bool flag7 = false;
            bool flag8 = false;
            bool flag9 = false;
            bool flag10 = false;
            bool page_flag1 = false;
            bool page_flag2 = false;
            bool page_flag3 = false;
            bool page_flag4 = false;
            bool label_flag = false;


            //当前页等于总页数
            if (currentPage == pages)
            {
                flag10 = true;
                flag8 = true;
            }

            //首页 flag5
            if (-10 == currentPage)
            {
                flag5 = true;
                flag7 = true;
                currentPage = 1;
            }

            //尾页  flag6
            if (-1 == currentPage)
            {
                flag6 = true;
                flag10 = true;
                currentPage = pages;
            }

            //上一页 flag7
            if (-5 == currentPage)
            {
                if (flag <= 0)
                {
                    flag7 = true;
                    flag9 = true;
                    flag5 = true;
                    currentPage = 1;
                }
                else
                {
                    flag7 = true;
                    currentPage = flag;
                }
            }

            //下一页 flag8
            if (-6 == currentPage)
            {
                if (flag >= pages)
                {
                    flag8 = true;
                    flag4 = true;
                    flag10 = true;
                    currentPage = pages;
                }
                else
                {
                    flag8 = true;
                    currentPage = flag;
                }

            }
            if (currentPage <= 2 && pages >= 4)
            {//当前显示第一页分页数据,并且总页数大于等于4。四个按钮都显示
                button1 = 1;
                button2 = 2;
                button3 = pages - 1;
                button4 = pages;

            }
            else if (currentPage > 2 && pages >= 4)
            {
                button1 = pages - 3;
                button2 = pages - 2;
                button3 = pages - 1;
                button4 = pages;
            }
            else if (pages == 3)
            {
                button1 = pages - 2;
                button2 = pages - 1;
                button3 = pages;
                button4 = 0;

            }
            else if (pages == 2)
            {
                button1 = pages - 1;
                button2 = pages;
                button3 = 0;
                button4 = 0;

            }
            else if (pages == 1)
            {
                button1 = pages;
                button2 = 0;
                button3 = 0;
                button4 = 0;

            }

            //右角下标拼接
            string str = "共 ";
            str += pages;
            str += " 页 ，";
            str += size;
            str += " 条数据";

            //当前页对应哪个按钮的判断
            if (button1 == currentPage)
            {
                flag1 = true;
            }

            if (button2 == currentPage)
            {
                flag2 = true;
            }

            if (button3 == currentPage)
            {
                flag3 = true;
            }
            if (button4 == currentPage)
            {
                flag4 = true;
            }

            if (pages >= 1)
            {
                page_flag1 = true;
            }

            if (pages >= 2)
            {
                page_flag2 = true;
            }

            if (pages >= 3)
            {
                page_flag3 = true;
            }

            if (pages >= 4)
            {
                page_flag4 = true;
            }

            //是否显示省略号的判断
            if (pages > 4)
            {
                label_flag = true;
            }
            Pages page = new Pages();
            page.count = PageSize;
            page.pages = pages;
            page.sum = size;
            page.button1 = button1;
            page.button2 = button2;
            page.button3 = button3;
            page.button4 = button4;
            page.currentPage = currentPage;
            page.text = str;
            page.flag1 = flag1;
            page.flag2 = flag2;
            page.flag3 = flag3;
            page.flag4 = flag4;
            page.flag5 = flag5;
            page.flag6 = flag6;
            page.flag7 = flag7;
            page.flag8 = flag8;
            page.flag9 = flag9;
            page.flag10 = flag10;
            page.page_flag1 = page_flag1;
            page.page_flag2 = page_flag2;
            page.page_flag3 = page_flag3;
            page.page_flag4 = page_flag4;
            page.label_flag = label_flag;
            return page;
        }
        //封装分页实体类
        public static Pages GetPages(List<SwitchData> SwitchData, int currentPage, int flag)
        {
            int size;
            //查询数据总数`
            if (SwitchData == null)
            {
                size = 0;
            }
            else
            {
                size = SwitchData.Count();
            }
             int pages;
            if (size > 0)
            {
                //计算总页数
                if (size % PageSize == 0)
                {
                    pages = size / PageSize;
                }
                else
                {
                    pages = size / PageSize + 1;
                }
            }
            else
            {
                pages = 1;
            }

            int button1 = 0;//定义按钮1的初始文本值
            int button2 = 0;//定义按钮2的初始文本值
            int button3 = 0;//定义按钮3的初始文本值
            int button4 = 0;//定义按钮4的初始文本值

            //初始化各种判断条件
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;
            bool flag7 = false;
            bool flag8 = false;
            bool flag9 = false;
            bool flag10 = false;
            bool page_flag1 = false;
            bool page_flag2 = false;
            bool page_flag3 = false;
            bool page_flag4 = false;
            bool label_flag = false;


            //当前页等于总页数
            if (currentPage == pages)
            {
                flag10 = true;
                flag8 = true;
            }

            //首页 flag5
            if (-10 == currentPage)
            {
                flag5 = true;
                flag7 = true;
                currentPage = 1;
            }

            //尾页  flag6
            if (-1 == currentPage)
            {
                flag6 = true;
                flag10 = true;
                currentPage = pages;
            }

            //上一页 flag7
            if (-5 == currentPage)
            {
                if (flag <= 0)
                {
                    flag7 = true;
                    flag9 = true;
                    flag5 = true;
                    currentPage = 1;
                }
                else
                {
                    flag7 = true;
                    currentPage = flag;
                }
            }

            //下一页 flag8
            if (-6 == currentPage)
            {
                if (flag >= pages)
                {
                    flag8 = true;
                    flag4 = true;
                    flag10 = true;
                    currentPage = pages;
                }
                else
                {
                    flag8 = true;
                    currentPage = flag;
                }

            }
            if (currentPage <= 2 && pages >= 4)
            {//当前显示第一页分页数据,并且总页数大于等于4。四个按钮都显示
                button1 = 1;
                button2 = 2;
                button3 = pages - 1;
                button4 = pages;

            }
            else if (currentPage > 2 && pages >= 4)
            {
                button1 = pages - 3;
                button2 = pages - 2;
                button3 = pages - 1;
                button4 = pages;
            }
            else if (pages == 3)
            {
                button1 = pages - 2;
                button2 = pages - 1;
                button3 = pages;
                button4 = 0;

            }
            else if (pages == 2)
            {
                button1 = pages - 1;
                button2 = pages;
                button3 = 0;
                button4 = 0;

            }
            else if (pages == 1)
            {
                button1 = pages;
                button2 = 0;
                button3 = 0;
                button4 = 0;

            }

            //右角下标拼接
            string str = "共 ";
            str += pages;
            str += " 页 ，";
            str += size;
            str += " 条数据";

            //当前页对应哪个按钮的判断
            if (button1 == currentPage)
            {
                flag1 = true;
            }

            if (button2 == currentPage)
            {
                flag2 = true;
            }

            if (button3 == currentPage)
            {
                flag3 = true;
            }
            if (button4 == currentPage)
            {
                flag4 = true;
            }

            if (pages >= 1)
            {
                page_flag1 = true;
            }

            if (pages >= 2)
            {
                page_flag2 = true;
            }

            if (pages >= 3)
            {
                page_flag3 = true;
            }

            if (pages >= 4)
            {
                page_flag4 = true;
            }

            //是否显示省略号的判断
            if (pages > 4)
            {
                label_flag = true;
            }
            Pages page = new Pages();
            page.count = PageSize;
            page.pages = pages;
            page.sum = size;
            page.button1 = button1;
            page.button2 = button2;
            page.button3 = button3;
            page.button4 = button4;
            page.currentPage = currentPage;
            page.text = str;
            page.flag1 = flag1;
            page.flag2 = flag2;
            page.flag3 = flag3;
            page.flag4 = flag4;
            page.flag5 = flag5;
            page.flag6 = flag6;
            page.flag7 = flag7;
            page.flag8 = flag8;
            page.flag9 = flag9;
            page.flag10 = flag10;
            page.page_flag1 = page_flag1;
            page.page_flag2 = page_flag2;
            page.page_flag3 = page_flag3;
            page.page_flag4 = page_flag4;
            page.label_flag = label_flag;
            return page;
        }

        //历史数据表
        public static Pages GetPages(List<HistoryData> SwitchData, int currentPage, int flag)
        {
            int size;
            //查询数据总数`
            if (SwitchData == null)
            {
                size = 0;
            }
            else
            {
                size = SwitchData.Count();
            }
            int pages;
            if (size > 0)
            {
                //计算总页数
                if (size % PageSize == 0)
                {
                    pages = size / PageSize;
                }
                else
                {
                    pages = size / PageSize + 1;
                }
            }
            else
            {
                pages = 1;
            }

            int button1 = 0;//定义按钮1的初始文本值
            int button2 = 0;//定义按钮2的初始文本值
            int button3 = 0;//定义按钮3的初始文本值
            int button4 = 0;//定义按钮4的初始文本值

            //初始化各种判断条件
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;
            bool flag7 = false;
            bool flag8 = false;
            bool flag9 = false;
            bool flag10 = false;
            bool page_flag1 = false;
            bool page_flag2 = false;
            bool page_flag3 = false;
            bool page_flag4 = false;
            bool label_flag = false;


            //当前页等于总页数
            if (currentPage == pages)
            {
                flag10 = true;
                flag8 = true;
            }

            //首页 flag5
            if (-10 == currentPage)
            {
                flag5 = true;
                flag7 = true;
                currentPage = 1;
            }

            //尾页  flag6
            if (-1 == currentPage)
            {
                flag6 = true;
                flag10 = true;
                currentPage = pages;
            }

            //上一页 flag7
            if (-5 == currentPage)
            {
                if (flag <= 0)
                {
                    flag7 = true;
                    flag9 = true;
                    flag5 = true;
                    currentPage = 1;
                }
                else
                {
                    flag7 = true;
                    currentPage = flag;
                }
            }

            //下一页 flag8
            if (-6 == currentPage)
            {
                if (flag >= pages)
                {
                    flag8 = true;
                    flag4 = true;
                    flag10 = true;
                    currentPage = pages;
                }
                else
                {
                    flag8 = true;
                    currentPage = flag;
                }

            }
            if (currentPage <= 2 && pages >= 4)
            {//当前显示第一页分页数据,并且总页数大于等于4。四个按钮都显示
                button1 = 1;
                button2 = 2;
                button3 = pages - 1;
                button4 = pages;

            }
            else if (currentPage > 2 && pages >= 4)
            {
                button1 = pages - 3;
                button2 = pages - 2;
                button3 = pages - 1;
                button4 = pages;
            }
            else if (pages == 3)
            {
                button1 = pages - 2;
                button2 = pages - 1;
                button3 = pages;
                button4 = 0;

            }
            else if (pages == 2)
            {
                button1 = pages - 1;
                button2 = pages;
                button3 = 0;
                button4 = 0;

            }
            else if (pages == 1)
            {
                button1 = pages;
                button2 = 0;
                button3 = 0;
                button4 = 0;

            }

            //右角下标拼接
            string str = "共 ";
            str += pages;
            str += " 页 ，";
            str += size;
            str += " 条数据";

            //当前页对应哪个按钮的判断
            if (button1 == currentPage)
            {
                flag1 = true;
            }

            if (button2 == currentPage)
            {
                flag2 = true;
            }

            if (button3 == currentPage)
            {
                flag3 = true;
            }
            if (button4 == currentPage)
            {
                flag4 = true;
            }

            if (pages >= 1)
            {
                page_flag1 = true;
            }

            if (pages >= 2)
            {
                page_flag2 = true;
            }

            if (pages >= 3)
            {
                page_flag3 = true;
            }

            if (pages >= 4)
            {
                page_flag4 = true;
            }

            //是否显示省略号的判断
            if (pages > 4)
            {
                label_flag = true;
            }
            Pages page = new Pages();
            page.count = PageSize;
            page.pages = pages;
            page.sum = size;
            page.button1 = button1;
            page.button2 = button2;
            page.button3 = button3;
            page.button4 = button4;
            page.currentPage = currentPage;
            page.text = str;
            page.flag1 = flag1;
            page.flag2 = flag2;
            page.flag3 = flag3;
            page.flag4 = flag4;
            page.flag5 = flag5;
            page.flag6 = flag6;
            page.flag7 = flag7;
            page.flag8 = flag8;
            page.flag9 = flag9;
            page.flag10 = flag10;
            page.page_flag1 = page_flag1;
            page.page_flag2 = page_flag2;
            page.page_flag3 = page_flag3;
            page.page_flag4 = page_flag4;
            page.label_flag = label_flag;
            return page;
        }
        public static Pages GetPages(List<ChargeRecord> SwitchData, int currentPage, int flag)
        {
            int size;
            //查询数据总数`
            if (SwitchData == null)
            {
                size = 0;
            }
            else
            {
                size = SwitchData.Count();
            }
            int pages;
            if (size > 0)
            {
                //计算总页数
                if (size % PageSize == 0)
                {
                    pages = size / PageSize;
                }
                else
                {
                    pages = size / PageSize + 1;
                }
            }
            else
            {
                pages = 1;
            }

            int button1 = 0;//定义按钮1的初始文本值
            int button2 = 0;//定义按钮2的初始文本值
            int button3 = 0;//定义按钮3的初始文本值
            int button4 = 0;//定义按钮4的初始文本值

            //初始化各种判断条件
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;
            bool flag7 = false;
            bool flag8 = false;
            bool flag9 = false;
            bool flag10 = false;
            bool page_flag1 = false;
            bool page_flag2 = false;
            bool page_flag3 = false;
            bool page_flag4 = false;
            bool label_flag = false;


            //当前页等于总页数
            if (currentPage == pages)
            {
                flag10 = true;
                flag8 = true;
            }

            //首页 flag5
            if (-10 == currentPage)
            {
                flag5 = true;
                flag7 = true;
                currentPage = 1;
            }

            //尾页  flag6
            if (-1 == currentPage)
            {
                flag6 = true;
                flag10 = true;
                currentPage = pages;
            }

            //上一页 flag7
            if (-5 == currentPage)
            {
                if (flag <= 0)
                {
                    flag7 = true;
                    flag9 = true;
                    flag5 = true;
                    currentPage = 1;
                }
                else
                {
                    flag7 = true;
                    currentPage = flag;
                }
            }

            //下一页 flag8
            if (-6 == currentPage)
            {
                if (flag >= pages)
                {
                    flag8 = true;
                    flag4 = true;
                    flag10 = true;
                    currentPage = pages;
                }
                else
                {
                    flag8 = true;
                    currentPage = flag;
                }

            }
            if (currentPage <= 2 && pages >= 4)
            {//当前显示第一页分页数据,并且总页数大于等于4。四个按钮都显示
                button1 = 1;
                button2 = 2;
                button3 = pages - 1;
                button4 = pages;

            }
            else if (currentPage > 2 && pages >= 4)
            {
                button1 = pages - 3;
                button2 = pages - 2;
                button3 = pages - 1;
                button4 = pages;
            }
            else if (pages == 3)
            {
                button1 = pages - 2;
                button2 = pages - 1;
                button3 = pages;
                button4 = 0;

            }
            else if (pages == 2)
            {
                button1 = pages - 1;
                button2 = pages;
                button3 = 0;
                button4 = 0;

            }
            else if (pages == 1)
            {
                button1 = pages;
                button2 = 0;
                button3 = 0;
                button4 = 0;

            }

            //右角下标拼接
            string str = "共 ";
            str += pages;
            str += " 页 ，";
            str += size;
            str += " 条数据";

            //当前页对应哪个按钮的判断
            if (button1 == currentPage)
            {
                flag1 = true;
            }

            if (button2 == currentPage)
            {
                flag2 = true;
            }

            if (button3 == currentPage)
            {
                flag3 = true;
            }
            if (button4 == currentPage)
            {
                flag4 = true;
            }

            if (pages >= 1)
            {
                page_flag1 = true;
            }

            if (pages >= 2)
            {
                page_flag2 = true;
            }

            if (pages >= 3)
            {
                page_flag3 = true;
            }

            if (pages >= 4)
            {
                page_flag4 = true;
            }

            //是否显示省略号的判断
            if (pages > 4)
            {
                label_flag = true;
            }
            Pages page = new Pages();
            page.count = PageSize;
            page.pages = pages;
            page.sum = size;
            page.button1 = button1;
            page.button2 = button2;
            page.button3 = button3;
            page.button4 = button4;
            page.currentPage = currentPage;
            page.text = str;
            page.flag1 = flag1;
            page.flag2 = flag2;
            page.flag3 = flag3;
            page.flag4 = flag4;
            page.flag5 = flag5;
            page.flag6 = flag6;
            page.flag7 = flag7;
            page.flag8 = flag8;
            page.flag9 = flag9;
            page.flag10 = flag10;
            page.page_flag1 = page_flag1;
            page.page_flag2 = page_flag2;
            page.page_flag3 = page_flag3;
            page.page_flag4 = page_flag4;
            page.label_flag = label_flag;
            return page;
        }


        //断复电记录数据表
        public static Pages GetPages(List<OffPower> SwitchData, int currentPage, int flag)
        {
            int size;
            //查询数据总数`
            if (SwitchData == null)
            {
                size = 0;
            }
            else
            {
                size = SwitchData.Count();
            }
            int pages;
            if (size > 0)
            {
                //计算总页数
                if (size % PageSize == 0)
                {
                    pages = size / PageSize;
                }
                else
                {
                    pages = size / PageSize + 1;
                }
            }
            else
            {
                pages = 1;
            }

            int button1 = 0;//定义按钮1的初始文本值
            int button2 = 0;//定义按钮2的初始文本值
            int button3 = 0;//定义按钮3的初始文本值
            int button4 = 0;//定义按钮4的初始文本值

            //初始化各种判断条件
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;
            bool flag7 = false;
            bool flag8 = false;
            bool flag9 = false;
            bool flag10 = false;
            bool page_flag1 = false;
            bool page_flag2 = false;
            bool page_flag3 = false;
            bool page_flag4 = false;
            bool label_flag = false;


            //当前页等于总页数
            if (currentPage == pages)
            {
                flag10 = true;
                flag8 = true;
            }

            //首页 flag5
            if (-10 == currentPage)
            {
                flag5 = true;
                flag7 = true;
                currentPage = 1;
            }

            //尾页  flag6
            if (-1 == currentPage)
            {
                flag6 = true;
                flag10 = true;
                currentPage = pages;
            }

            //上一页 flag7
            if (-5 == currentPage)
            {
                if (flag <= 0)
                {
                    flag7 = true;
                    flag9 = true;
                    flag5 = true;
                    currentPage = 1;
                }
                else
                {
                    flag7 = true;
                    currentPage = flag;
                }
            }

            //下一页 flag8
            if (-6 == currentPage)
            {
                if (flag >= pages)
                {
                    flag8 = true;
                    flag4 = true;
                    flag10 = true;
                    currentPage = pages;
                }
                else
                {
                    flag8 = true;
                    currentPage = flag;
                }

            }
            if (currentPage <= 2 && pages >= 4)
            {//当前显示第一页分页数据,并且总页数大于等于4。四个按钮都显示
                button1 = 1;
                button2 = 2;
                button3 = pages - 1;
                button4 = pages;

            }
            else if (currentPage > 2 && pages >= 4)
            {
                button1 = pages - 3;
                button2 = pages - 2;
                button3 = pages - 1;
                button4 = pages;
            }
            else if (pages == 3)
            {
                button1 = pages - 2;
                button2 = pages - 1;
                button3 = pages;
                button4 = 0;

            }
            else if (pages == 2)
            {
                button1 = pages - 1;
                button2 = pages;
                button3 = 0;
                button4 = 0;

            }
            else if (pages == 1)
            {
                button1 = pages;
                button2 = 0;
                button3 = 0;
                button4 = 0;

            }

            //右角下标拼接
            string str = "共 ";
            str += pages;
            str += " 页 ，";
            str += size;
            str += " 条数据";

            //当前页对应哪个按钮的判断
            if (button1 == currentPage)
            {
                flag1 = true;
            }

            if (button2 == currentPage)
            {
                flag2 = true;
            }

            if (button3 == currentPage)
            {
                flag3 = true;
            }
            if (button4 == currentPage)
            {
                flag4 = true;
            }

            if (pages >= 1)
            {
                page_flag1 = true;
            }

            if (pages >= 2)
            {
                page_flag2 = true;
            }

            if (pages >= 3)
            {
                page_flag3 = true;
            }

            if (pages >= 4)
            {
                page_flag4 = true;
            }

            //是否显示省略号的判断
            if (pages > 4)
            {
                label_flag = true;
            }
            Pages page = new Pages();
            page.count = PageSize;
            page.pages = pages;
            page.sum = size;
            page.button1 = button1;
            page.button2 = button2;
            page.button3 = button3;
            page.button4 = button4;
            page.currentPage = currentPage;
            page.text = str;
            page.flag1 = flag1;
            page.flag2 = flag2;
            page.flag3 = flag3;
            page.flag4 = flag4;
            page.flag5 = flag5;
            page.flag6 = flag6;
            page.flag7 = flag7;
            page.flag8 = flag8;
            page.flag9 = flag9;
            page.flag10 = flag10;
            page.page_flag1 = page_flag1;
            page.page_flag2 = page_flag2;
            page.page_flag3 = page_flag3;
            page.page_flag4 = page_flag4;
            page.label_flag = label_flag;
            return page;
        }

        //报警记录数据表
        public static Pages GetPages(List<AlarmData> SwitchData, int currentPage, int flag)
        {
            int size;
            //查询数据总数`
            if (SwitchData == null)
            {
                size = 0;
            }
            else
            {
                size = SwitchData.Count();
            }
            int pages;
            if (size > 0)
            {
                //计算总页数
                if (size % PageSize == 0)
                {
                    pages = size / PageSize;
                }
                else
                {
                    pages = size / PageSize + 1;
                }
            }
            else
            {
                pages = 1;
            }

            int button1 = 0;//定义按钮1的初始文本值
            int button2 = 0;//定义按钮2的初始文本值
            int button3 = 0;//定义按钮3的初始文本值
            int button4 = 0;//定义按钮4的初始文本值

            //初始化各种判断条件
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;
            bool flag7 = false;
            bool flag8 = false;
            bool flag9 = false;
            bool flag10 = false;
            bool page_flag1 = false;
            bool page_flag2 = false;
            bool page_flag3 = false;
            bool page_flag4 = false;
            bool label_flag = false;


            //当前页等于总页数
            if (currentPage == pages)
            {
                flag10 = true;
                flag8 = true;
            }

            //首页 flag5
            if (-10 == currentPage)
            {
                flag5 = true;
                flag7 = true;
                currentPage = 1;
            }

            //尾页  flag6
            if (-1 == currentPage)
            {
                flag6 = true;
                flag10 = true;
                currentPage = pages;
            }

            //上一页 flag7
            if (-5 == currentPage)
            {
                if (flag <= 0)
                {
                    flag7 = true;
                    flag9 = true;
                    flag5 = true;
                    currentPage = 1;
                }
                else
                {
                    flag7 = true;
                    currentPage = flag;
                }
            }

            //下一页 flag8
            if (-6 == currentPage)
            {
                if (flag >= pages)
                {
                    flag8 = true;
                    flag4 = true;
                    flag10 = true;
                    currentPage = pages;
                }
                else
                {
                    flag8 = true;
                    currentPage = flag;
                }

            }
            if (currentPage <= 2 && pages >= 4)
            {//当前显示第一页分页数据,并且总页数大于等于4。四个按钮都显示
                button1 = 1;
                button2 = 2;
                button3 = pages - 1;
                button4 = pages;

            }
            else if (currentPage > 2 && pages >= 4)
            {
                button1 = pages - 3;
                button2 = pages - 2;
                button3 = pages - 1;
                button4 = pages;
            }
            else if (pages == 3)
            {
                button1 = pages - 2;
                button2 = pages - 1;
                button3 = pages;
                button4 = 0;

            }
            else if (pages == 2)
            {
                button1 = pages - 1;
                button2 = pages;
                button3 = 0;
                button4 = 0;

            }
            else if (pages == 1)
            {
                button1 = pages;
                button2 = 0;
                button3 = 0;
                button4 = 0;

            }

            //右角下标拼接
            string str = "共 ";
            str += pages;
            str += " 页 ，";
            str += size;
            str += " 条数据";

            //当前页对应哪个按钮的判断
            if (button1 == currentPage)
            {
                flag1 = true;
            }

            if (button2 == currentPage)
            {
                flag2 = true;
            }

            if (button3 == currentPage)
            {
                flag3 = true;
            }
            if (button4 == currentPage)
            {
                flag4 = true;
            }

            if (pages >= 1)
            {
                page_flag1 = true;
            }

            if (pages >= 2)
            {
                page_flag2 = true;
            }

            if (pages >= 3)
            {
                page_flag3 = true;
            }

            if (pages >= 4)
            {
                page_flag4 = true;
            }

            //是否显示省略号的判断
            if (pages > 4)
            {
                label_flag = true;
            }
            Pages page = new Pages();
            page.count = PageSize;
            page.pages = pages;
            page.sum = size;
            page.button1 = button1;
            page.button2 = button2;
            page.button3 = button3;
            page.button4 = button4;
            page.currentPage = currentPage;
            page.text = str;
            page.flag1 = flag1;
            page.flag2 = flag2;
            page.flag3 = flag3;
            page.flag4 = flag4;
            page.flag5 = flag5;
            page.flag6 = flag6;
            page.flag7 = flag7;
            page.flag8 = flag8;
            page.flag9 = flag9;
            page.flag10 = flag10;
            page.page_flag1 = page_flag1;
            page.page_flag2 = page_flag2;
            page.page_flag3 = page_flag3;
            page.page_flag4 = page_flag4;
            page.label_flag = label_flag;
            return page;
        }

        public static Pages GetPages(ObservableCollection<Immediate> SwitchData, int currentPage, int flag)
        {
            int size;
            //查询数据总数`
            if (SwitchData == null)
            {
                size = 0;
            }
            else
            {
                size = SwitchData.Count();
            }
            int pages;
            if (size > 0)
            {
                //计算总页数
                if (size % PageSize == 0)
                {
                    pages = size / PageSize;
                }
                else
                {
                    pages = size / PageSize + 1;
                }
            }
            else
            {
                pages = 1;
            }

            int button1 = 0;//定义按钮1的初始文本值
            int button2 = 0;//定义按钮2的初始文本值
            int button3 = 0;//定义按钮3的初始文本值
            int button4 = 0;//定义按钮4的初始文本值

            //初始化各种判断条件
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;
            bool flag7 = false;
            bool flag8 = false;
            bool flag9 = false;
            bool flag10 = false;
            bool page_flag1 = false;
            bool page_flag2 = false;
            bool page_flag3 = false;
            bool page_flag4 = false;
            bool label_flag = false;


            //当前页等于总页数
            if (currentPage == pages)
            {
                flag10 = true;
                flag8 = true;
            }

            //首页 flag5
            if (-10 == currentPage)
            {
                flag5 = true;
                flag7 = true;
                currentPage = 1;
            }

            //尾页  flag6
            if (-1 == currentPage)
            {
                flag6 = true;
                flag10 = true;
                currentPage = pages;
            }

            //上一页 flag7
            if (-5 == currentPage)
            {
                if (flag <= 0)
                {
                    flag7 = true;
                    flag9 = true;
                    flag5 = true;
                    currentPage = 1;
                }
                else
                {
                    flag7 = true;
                    currentPage = flag;
                }
            }

            //下一页 flag8
            if (-6 == currentPage)
            {
                if (flag >= pages)
                {
                    flag8 = true;
                    flag4 = true;
                    flag10 = true;
                    currentPage = pages;
                }
                else
                {
                    flag8 = true;
                    currentPage = flag;
                }

            }
            if (currentPage <= 2 && pages >= 4)
            {//当前显示第一页分页数据,并且总页数大于等于4。四个按钮都显示
                button1 = 1;
                button2 = 2;
                button3 = pages - 1;
                button4 = pages;

            }
            else if (currentPage > 2 && pages >= 4)
            {
                button1 = pages - 3;
                button2 = pages - 2;
                button3 = pages - 1;
                button4 = pages;
            }
            else if (pages == 3)
            {
                button1 = pages - 2;
                button2 = pages - 1;
                button3 = pages;
                button4 = 0;

            }
            else if (pages == 2)
            {
                button1 = pages - 1;
                button2 = pages;
                button3 = 0;
                button4 = 0;

            }
            else if (pages == 1)
            {
                button1 = pages;
                button2 = 0;
                button3 = 0;
                button4 = 0;

            }

            //右角下标拼接
            string str = "共 ";
            str += pages;
            str += " 页 ，";
            str += size;
            str += " 条数据";

            //当前页对应哪个按钮的判断
            if (button1 == currentPage)
            {
                flag1 = true;
            }

            if (button2 == currentPage)
            {
                flag2 = true;
            }

            if (button3 == currentPage)
            {
                flag3 = true;
            }
            if (button4 == currentPage)
            {
                flag4 = true;
            }

            if (pages >= 1)
            {
                page_flag1 = true;
            }

            if (pages >= 2)
            {
                page_flag2 = true;
            }

            if (pages >= 3)
            {
                page_flag3 = true;
            }

            if (pages >= 4)
            {
                page_flag4 = true;
            }

            //是否显示省略号的判断
            if (pages > 4)
            {
                label_flag = true;
            }
            Pages page = new Pages();
            page.count = PageSize;
            page.pages = pages;
            page.sum = size;
            page.button1 = button1;
            page.button2 = button2;
            page.button3 = button3;
            page.button4 = button4;
            page.currentPage = currentPage;
            page.text = str;
            page.flag1 = flag1;
            page.flag2 = flag2;
            page.flag3 = flag3;
            page.flag4 = flag4;
            page.flag5 = flag5;
            page.flag6 = flag6;
            page.flag7 = flag7;
            page.flag8 = flag8;
            page.flag9 = flag9;
            page.flag10 = flag10;
            page.page_flag1 = page_flag1;
            page.page_flag2 = page_flag2;
            page.page_flag3 = page_flag3;
            page.page_flag4 = page_flag4;
            page.label_flag = label_flag;
            return page;
        }

        //显示每页数据
        public static List<T> data<T>(List<T> ts, int currentPage)
        {
            List<T> dataTs = new List<T>();
            //计算当前页数据的开始索引
            int firstData = (currentPage - 1) * PageSize;
            //计算当前页数据的结束索引
            int lastData = currentPage * PageSize - 1;
            for (int a = 0; a < ts.Count; a++)
            {
                if (a >= firstData && a <= lastData)
                {
                    dataTs.Add(ts[a]);
                }
            }
            return dataTs;
        }

        public static ObservableCollection<T> data1<T>(ObservableCollection<T> ts, int currentPage)
        {
            ObservableCollection<T> dataTs = new ObservableCollection<T>();
            //计算当前页数据的开始索引
            int firstData = (currentPage - 1) * PageSize;
            //计算当前页数据的结束索引
            int lastData = currentPage * PageSize - 1;
            for (int a = 0; a < ts.Count; a++)
            {
                if (a >= firstData && a <= lastData)
                {
                    dataTs.Add(ts[a]);
                }
            }
            return dataTs;
        }
    }
}

